﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Web.Configuration;

public partial class product_iPad : System.Web.UI.Page
{
    private SqlConnection connect;
    private SqlDataAdapter da;
    private SqlCommand command;
    private DataSet ds;
    private string connectionString;

    protected void Page_Load(object sender, EventArgs e)
    {
        connectionString = WebConfigurationManager.ConnectionStrings["AppleShopConnectionString"].ToString();
        connect = new SqlConnection(connectionString);
        connect.Open();

        if (!IsPostBack)
        {
            bindDataToDataList();
        }
    }
    protected void bindDataToDataList()
    {
        try
        {
            if (connect.State == ConnectionState.Closed)
            {
                connect.Open();
            }
            ds = new DataSet();
            command = new SqlCommand("spGetProduct_iPad", connect);
            command.CommandType = CommandType.StoredProcedure;
            da = new SqlDataAdapter(command);
            da.Fill(ds);
            dataListIPad.DataSource = ds.Tables[0];
            dataListIPad.DataBind();

        }
        catch (SqlException ex)
        {
            throw new Exception(ex.Message);
        }
        finally
        {
            connect.Close();
        }
    }

    
    protected void dataListIPad_ItemCommand(object source, DataListCommandEventArgs e)
    {
        if (e.CommandName == "ProductIPad")
        {
            Session["IPadDetails"] = e.CommandArgument.ToString();
            Response.Redirect("product-iPadDetails.aspx?ID=" + e.CommandArgument.ToString());
        }
    }
}